﻿// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"

//配置部分
int yourdata = 0;
char ModuleName[MAX_PATH] = "HongHuangXianShi";
BOOL IsOn = FALSE;
BYTE KeyCode = 0xFF;
BYTE ReloadKeyCode = 0xFF;

void LoadCFG()
{
	IsOn = cfgload::GetModuleIsOn(ModuleName);
	KeyCode = cfgload::GetModuleHotKey(ModuleName);
	ReloadKeyCode = cfgload::GetModuleHotKey("Reload cfg");
}

void Trigger()
{
	CHAR info[MAX_PATH] = "";
	cfgload::GetModuleDescription(ModuleName, info, MAX_PATH);
	if (IsOn)
	{
		IsOn = FALSE;
		D2Functions::GameInfof("$$9Module %s $$0:$$1OFF", info);
	}
	else
	{
		IsOn = TRUE;
		D2Functions::GameInfof("$$9Module %s $$0:$$2ON", info);
	}
}

extern "C"
{
	void __declspec(dllexport) DllGameLoop(GamePub* pGamePub)
	{
		//游戏内的GameLoop
	}

	void __declspec(dllexport) DllGameRunOnce(GamePub* pGamePub)
	{
		LoadCFG();
		//进入房间运行一次
	}

	void __declspec(dllexport)DllGameEnd(GamePub* pGamePub)
	{
		//退出房间时运行一次
	}

	void __declspec(dllexport)DllGamePacketReceived(BYTE* aPacket, DWORD aLength, GamePub* pGamePub)
	{
		//在游戏接受到数据包时处理
	}

	void __declspec(dllexport)DllGameCommandLine(char** argv, int argc, GamePub* pGamePub)
	{
		//游戏内发送.文本处理
	}

	void __declspec(dllexport)DllGamePacketSent(BYTE* aPacket, DWORD aLength, GamePub* pGamePub)
	{
		//在游戏发送数据包时处理
	}

	void __declspec(dllexport)DllGameKeyDown(BYTE keycode, BYTE repeat, GamePub* pGamePub)
	{
		//游戏内按键处理
		if (keycode == 0xFF)return;

		if (keycode == ReloadKeyCode)
		{
			IsOn = FALSE;
			LoadCFG();
		}
		else if (keycode == KeyCode)
		{
			Trigger();
		}
		if (keycode == VK_NUMPAD0)
		{

		}
		//添加处理的代码
	}

	void __declspec(dllexport)DllGameDrawClient(GamePub* pGamePub)
	{
		if (D2Client::D2GetUIToggle(UIVAR_STATS))
		{
			int x = 220;
			int y = 300;
			int value1 = 0;//洪荒等级
			int value2 = 0;//洪荒等级
			char info[MAX_PATH] = "";
			D2Functions::DrawCenterText(0, "洪荒显示", x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1085);//火洪荒
			value2 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 333, 0);//火穿刺
			sprintf_s(info, MAX_PATH, "$$1火洪荒:$$0%d $$1火穿:$$0%d $$1穿:$$0%d $$1总:$$0%d", value1, value2, value1 ? 42 + value1 * 8 + value2:value2, value1+ value2/8);
			D2Functions::DrawCenterText(0, info, x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1087);//电洪荒
			value2 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 334, 0);//电穿刺
			sprintf_s(info, MAX_PATH, "$$9电洪荒:$$0%d $$9电穿:$$0%d $$9穿:$$0%d $$9总:$$0%d", value1, value2, value1 ? 42 + value1 * 8 + value2 : value2, value1 + value2 / 8);
			D2Functions::DrawCenterText(0, info, x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1086);//冰洪荒
			value2 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 335, 0);//冰穿刺
			sprintf_s(info, MAX_PATH, "$$3冰洪荒:$$0%d $$3冰穿:$$0%d $$3穿:$$0%d $$3总:$$0%d", value1, value2, value1 ? 42 + value1 * 8 + value2 : value2, value1 + value2 / 8);
			D2Functions::DrawCenterText(0, info, x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1088);//毒洪荒
			value2 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 336, 0);//毒穿刺
			sprintf_s(info, MAX_PATH, "$$2毒洪荒:$$0%d $$2毒穿:$$0%d $$2穿:$$0%d $$2总:$$0%d", value1, value2, value1 ? 42 + value1 * 8 + value2 : value2, value1 + value2 / 8);
			D2Functions::DrawCenterText(0, info, x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1089);//魔洪荒
			value2 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 358, 0);//魔穿刺
			sprintf_s(info, MAX_PATH, "$$8魔洪荒:$$0%d $$8魔穿:$$0%d $$8穿:$$0%d $$8总:$$0%d", value1, value2, value1 ? 42 + value1 * 8 + value2 : value2, value1 + value2 / 8);
			D2Functions::DrawCenterText(0, info, x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1090);//物洪荒
			value2 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 407, 0);//物穿刺
			sprintf_s(info, MAX_PATH, "$$5物洪荒:$$0%d $$5物穿:$$0%d $$5穿:$$0%d $$5总:$$0%d", value1, value2, value1 ? 42 + value1 * 8 + value2 : value2, value1 + value2 / 8);
			D2Functions::DrawCenterText(0, info, x, y, 0);
			y += 16;
			value1 = D2Common::D2GetUnitStat(D2Client::D2GetPlayerClient(), 151, 1130);//凤凰之力
			sprintf_s(info, MAX_PATH, "$$1凤凰$$2之$$8力:$$0%d", value1);
			D2Functions::DrawCenterText(0, info, x, y, 0);
		}
		//你可以画一个小猪佩奇
	}

	void __declspec(dllexport)DllGameLoopThread(GamePub* pGamePub)
	{
		//这个比较准时 每0.01秒运行一次
	}
}

BOOL APIENTRY DllMain(HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

